package info.thereisonlywe.core.objects;

public class CircularArray<T> {

	private final T[] array;

	private int index = 0;

	public CircularArray(T[] array)
	{
		this.array = array;
	}

	// Use this constructor to copy a CircularArray object
	public CircularArray(CircularArray<T> another)
	{
		this.array = another.array;
		this.index = another.index;
	}

	public synchronized void goTo(int index)
	{
		if (index >= array.length) index = array.length - index;
		this.index = index;
	}

	public synchronized T next()
	{
		index++;
		if (index >= array.length) index = array.length - index;
		return array[index];
	}

	public synchronized T current()
	{
		return array[index];
	}
}
